package com.mes.schedule.manager.iface;

import java.util.Date;
import java.util.List;
import com.mes.common.exception.bo.BaseBusinessException;
import com.mes.common.exception.db.BaseDBException;
import com.mes.common.manager.iface.IBasicManager;
import com.mes.schedule.domain.ScheduleScheme;

/**
 * 调度主进程
 * 
 * @author Administrator
 * 
 */
public interface IScheduleManager extends IBasicManager, IScheduleAlgorithm {

	public final static int THREAD_TYPE_FIXED10 = 10;
	public final static int THREAD_TYPE_FIXED20 = 20;
	public final static int THREAD_TYPE_FIXED50 = 50;
	public final static int THREAD_TYPE_UNLIMITED = 100;

	/**
	 * get the schedule scheme by scheduleUid
	 * 
	 * @param scheduleUid
	 * @return ScheduleScheme
	 * @throws BaseDBException
	 * @throws Exception 
	 */
	public ScheduleScheme getScheduleByUid(String scheduleUid)
			throws BaseDBException, Exception;

	/**
	 * load the tasks to construct the task net
	 * 
	 * @param scheme
	 * @throws BaseDBException
	 */
	public void importTasks(ScheduleScheme scheme) throws Exception;

	public void finishScheme(ScheduleScheme scheme) throws BaseDBException, Exception;

	/**
	 * save the result of the schedule
	 * 
	 * @param scheme
	 * @throws BaseBusinessException
	 * @throws BaseDBException
	 */
	public void saveResult(ScheduleScheme scheme) throws BaseBusinessException,
			BaseDBException;

	/**
	 * 恢复调度方案
	 * 
	 * @param scheme
	 * @throws BaseBusinessException
	 * @throws BaseDBException
	 */
	public void restoreScheme(ScheduleScheme scheme) throws Exception;

	/**
	 * restore the result of the schedule
	 * 
	 * @param scheme
	 * @throws BaseBusinessException
	 * @throws BaseDBException
	 */
	public void openScheme(ScheduleScheme scheme) throws BaseBusinessException,
			BaseDBException;

	/**
	 * 添加新部门的能力计划方案
	 * 
	 * @param scheme
	 * @throws BaseBusinessException
	 * @throws BaseDBException
	 * @throws Exception 
	 */
	public void addDeptScheme(ScheduleScheme scheme)
			throws BaseBusinessException, BaseDBException, Exception;

	public void schemePartTaskPro(ScheduleScheme scheme) throws Exception;

	public void applySchedulePara(ScheduleScheme newScheme,
			ScheduleScheme originScheme) throws Exception;

	public void refreshSlackAndColor(ScheduleScheme scheme) throws Exception;

	/**
	 * 只更改调度集合中的松弛率与色带
	 * 
	 * @param scheme
	 * @throws Exception
	 */
	public void refreshScheduleSlackAndColor(ScheduleScheme scheme)
			throws Exception;

	/**
	 * 初始化调度范围
	 */
	public void initScheduleScope(ScheduleScheme scheme, Date scheduleStart,
			Date scheduleFinish) throws Exception;

	/**
	 * 设置调度当前时间，主要用于动态仿真
	 */
	public void setScheduleCurrentTime(ScheduleScheme scheme,
			Date scheduleCurrentTime) throws Exception;

	// /**
	// * 获取调度当前时间，主要用于动态仿真
	// 放在这里太不方便了
	// */
	// public Date getScheduleCurrentTime(ScheduleScheme scheme);

	/**
	 * 
	 * 根据任务状态、序列设备上的虚拟任务链接关系
	 * 
	 */
	public void createDeviceVLink(ScheduleScheme scheme);

	public void initWorkCenterMap(ScheduleScheme scheme) throws Exception;

	/**
	 * 调度后处理
	 * 
	 * @param scheme
	 * @param mode
	 */
	public void afterSchedule(ScheduleScheme scheme, int mode);

	/**
	 * 基于基准创建计划
	 * 
	 * @param scheme
	 */
	public void newScheduleSchemeOnBase(ScheduleScheme scheme);

	/**
	 * 基于原始计划创建方案（schedule+deptid） by hba
	 * 
	 * @param scheme
	 */
	public void newScheduleSchemeBasedOnOrigin(ScheduleScheme scheme);

	/**
	 * 主要用于两阶段算法，在设备都分配好之后快速分派任务
	 */
	public void schedulePhase(ScheduleScheme scheme);

	/**
	 * 迅速销毁schme
	 */
	public void destroyScheme(ScheduleScheme scheme);

	/**
	 * 一次调度一次整理
	 * 
	 * @param scheme
	 * @param mode
	 * @throws Exception
	 */
	public void beforeSchedule(ScheduleScheme scheme, int mode)
			throws Exception;

	/**
	 * 初始化虚拟资源
	 * 
	 * @param scheme
	 */
	public void initVirtualResource(ScheduleScheme scheme);

	/**
	 * 清除调度方案中的所有任务 主要用于重新生成调度方案
	 */
	public void clearAllTask(String scheduleUid) throws BaseBusinessException;

	/**
	 * copy scheduleResult
	 * 
	 * @param fromScheme
	 * @param toScheme
	 */
	public void copyScheduleResult(ScheduleScheme fromScheme,
			ScheduleScheme toScheme);

	/**
	 * 根据部门编号确定方案 by hba
	 * 
	 * @param deptId
	 * @param schemeType
	 * @return
	 */
	public List<ScheduleScheme> getScheduleByDeptId(String deptId,
			String schemeType);

	/**
	 * 获取具有相同基准方案的多个方案 by hba
	 * 
	 * @param baseScheduleUid
	 * @return
	 */
	public List<ScheduleScheme> getScheduleByBaseScheduleUid(
			String baseScheduleUid);

	/**
	 * 将调度方案恢复成原始数据 by hba
	 * 
	 * @param scheme
	 */
	public void restoreSchemeToOrigin(ScheduleScheme scheme);

	public void inheritBaseScheme(ScheduleScheme scheme) throws Exception;

	public void restoreSummaryScheme(ScheduleScheme scheme) throws Exception;
}
